package com.sxj.corejava.code17_模板模式;

import java.util.Arrays;

/**
 * @author 石小俊
 */
public class Test {

    public static void main(String[] args) {
        Integer[] arr = {9, 15, 3, 21, 6, 1, 8, 13, 10};
        // 升序
        SortTemplate.sort(arr, new SortComparator<Integer>() {
            @Override
            public int compareTo(Integer t1, Integer t2) {
                return t1 - t2;
            }
        });

        System.out.println(Arrays.toString(arr));
        // 降序
        SortTemplate.sort(arr,(t1,t2) -> (Integer)t2 - (Integer)t1);
        System.out.println(Arrays.toString(arr));

        String[] names = {"tom","admin","jack","zhangsan"};
        // 升序
        SortTemplate.sort(names, new SortComparator<String>() {
            @Override
            public int compareTo(String t1, String t2) {
                return t1.length() - t2.length();
            }
        });
        System.out.println(Arrays.toString(names));
        // 降序
        SortTemplate.sort(names, new SortComparator<String>() {
            @Override
            public int compareTo(String t1, String t2) {
                return t2.length() - t1.length();
            }
        });
        System.out.println(Arrays.toString(names));
    }

}
